package kr.hkit.androidcomplete03.ETC;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Chronometer;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


//예약시작 : 크로노미터를 클릭, 예약완료 : 연도를 롱클릭하면 동작
//크로노미터 클릭 : 라디어버튼 보임, 연도롱클릭 : 라디오버튼, 데이트피커, 타임피커 사라짐
public class WidgetTest2 extends Activity {
	Chronometer chrono;
	RadioGroup rdoGroup;
	RadioButton rdoCal, rdoTime;
	DatePicker datePicker;
	TextView tvYear, tvMonth, tvDay, tvHour, tvMinute;
	LinearLayout linearSec;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.widgettest2);
		
		linearSec = (LinearLayout) findViewById(R.id.linearSec);
		
		chrono = (Chronometer) findViewById(R.id.chronometer2);
		
		rdoGroup = (RadioGroup) findViewById(R.id.radioGroup2);
		rdoCal = (RadioButton) findViewById(R.id.radioDay);
		rdoTime = (RadioButton) findViewById(R.id.radioHour);
		
		datePicker = (DatePicker) findViewById(R.id.datePicker2);
		
		tvYear = (TextView) findViewById(R.id.tvYear2);
		tvMonth = (TextView) findViewById(R.id.tvMonth2);
		tvDay = (TextView) findViewById(R.id.tvDay2);
		tvHour = (TextView) findViewById(R.id.tvHour2);
		tvMinute = (TextView) findViewById(R.id.tvMinute2);
				
		rdoGroup.setVisibility(View.INVISIBLE);
		datePicker.setVisibility(View.INVISIBLE);
		
		chrono.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				rdoGroup.setVisibility(View.VISIBLE);
				datePicker.setVisibility(View.VISIBLE);
				chrono.setBase(SystemClock.elapsedRealtime());
				chrono.start();
				chrono.setTextColor(Color.RED);
				
			}
			
		});
		
		chrono.setOnLongClickListener(new View.OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				finish();
				return true;
			}
		});
		
		tvYear.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				chrono.stop();
				chrono.setTextColor(Color.BLUE);
			}
		});
		
		tvYear.setOnLongClickListener(new View.OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				datePicker.setVisibility(View.INVISIBLE);
				
				/*java.util.Date curDate = new java.util.Date(calView.getDate());
				
				tvYear.setText(Integer.toString(1900 + curDate.getYear()));
				tvMonth.setText(Integer.toString(1 + curDate.getMonth()));
				tvDay.setText(Integer.toString(curDate.getDate()));
				
				tvHour.setText(Integer.toString(dataP.getCurrentHour()));
				tvMinute.setText(Integer.toString(tPicker.getCurrentMinute()));*/
				return true;
			}
		});
	}
}
